<%@page import="entity.Course"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>管理页面</title>

  </head>
  
  <body>
                              <jsp:useBean id="user" class="entity.User" scope="session"></jsp:useBean>
                                    <jsp:include page="top.jsp"></jsp:include><br>
                                    <font color='blue'>欢迎使用本系统....</font><br><br>
                                    <% if("admin".equals(user.getUsername().trim()))
                                    { //若管理员登录，显示add页面%>
                                    <jsp:include page="add.jsp"></jsp:include><br>
                                     <% }%>
                                      
                                                                                      
     <%
        response.setContentType("text/html;charset=gbk");
		request.setCharacterEncoding("gbk");
		response.setCharacterEncoding("gbk");
         ArrayList<Course> clist = new ArrayList<Course>();
		clist=(ArrayList<Course>) request.getSession().getAttribute("list");//这个是课程的总信息list
		if("admin".equals(user.getUsername().trim()))
		{
		%>
		 <table border="1">
        <tr>
        <td colspan="7" align="center">课程信息表</td>
        </tr>
        <tr>
     
        <td>课程名字</td>
        <td>开课时间</td>
        <td>课程学分</td>
        <td>操作列表</td>
        </tr>
		<% 
		for(int i = 0; i< clist.size();i++) {
           %>  
        <tr>
            <td><%=clist.get(i).getName()%></td>
            <td><%=clist.get(i).getTerm()%></td>
            <td><%=clist.get(i).getCredit()%></td>
            <td><a href="servlet/removeservlet?id=<%=i%>">删除此纪录</a>
            <a href="edit.jsp?id=<%=i%>">修改此纪录</a></td>
            
            
            <%

            }
            %>
               </table><br><br>
           <%          
            }
            if("student".equals(user.getUsername().trim()))//学生看到的界面
            { 
           ArrayList<Course> chlist = new ArrayList<Course>();
		chlist=(ArrayList<Course>) request.getSession().getAttribute("chlist");//这个是学生选课的总信息chlist
            if(request.getSession().getAttribute("list")==null)
            {
            String errorInfo="无法选课，原因：管理员未导入课程信息，请联系管理员";
            request.setAttribute("errorInfo", errorInfo);
		    request.getRequestDispatcher("/stulogin.jsp").forward(request, response);}//转发error与页面跳转
		//request.getSession().setAttribute("chlist", chlist);//转发
		 %> 
		 <table border="1">
        <tr>
        <td colspan="7" align="center">课程信息表</td>
        </tr>
        <tr>
     
        <td>课程名字</td>
        <td>开课时间</td>
        <td>课程学分</td>
        <td>操作列表</td>
        </tr>
		<% 
		for(int i = 0; i< clist.size();i++) {
           %>  
        <tr>
            <td><%=clist.get(i).getName()%></td>
            <td><%=clist.get(i).getTerm()%></td>
            <td><%=clist.get(i).getCredit()%></td>
            <td><a href="servlet/chooseservlet?id=<%=i%>">选课</a></td>
            
            
            <%

            }
            %>
               </table><br><br>
           
         <table border="1">
        <tr>
        <td colspan="7" align="center">课选课信息表</td>
        </tr>
        <tr>
     
        <td>课程名字</td>
        <td>开课时间</td>
        <td>课程学分</td>
        <td>操作列表</td>
        </tr>
               <% 
		for(int i = 0; i< chlist.size();i++) {
           %>  
        <tr>
            <td><%=chlist.get(i).getName()%></td>
            <td><%=chlist.get(i).getTerm()%></td>
            <td><%=chlist.get(i).getCredit()%></td>
            <td><a href="servlet/chreservlet?id=<%=i%>">退选</a></td>
            
            
            <%

            }
            %>                     
       </table>                         
                                    
                                    
                                     <% }%>
                                    
                                   
        <a href="loginmain.jsp">退出登录</a>
        
        
        
        
        
        
        
                                                                               
                                                                                            
                                                                                            
                                                                                            
                                                                              

  </body>
</html>
